package com.laolei.config.client;

import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import com.fasterxml.jackson.databind.ObjectMapper;

@SpringBootApplication
public class SpringConfigClientApplication{

	public static void main(String[] args) {
		SpringApplication.run(SpringConfigClientApplication.class, args);
	}
	
	@Autowired ObjectMapper objectMapper;

	@ConfigurationProperties("config.dev")
	@Bean Map<String,Object> devConfig(){ return new LinkedHashMap<>(); }

	@ConfigurationProperties("config.global")
	@Bean Map<String,Object> globalConfig(){ return new LinkedHashMap<>(); }

	@ConfigurationProperties("config.laolei")
	@Bean Map<String,Object> laoleiConfig(){ return new LinkedHashMap<>(); }
	
	@Bean CommandLineRunner commandLineRunner(){
		return (args)->{
			System.err.println("这是dev环境的配置参数: "+objectMapper.writeValueAsString(devConfig()));
			System.err.println("这是全局的配置参数: "+objectMapper.writeValueAsString(globalConfig()));
			System.err.println("这是被包含的通用配置参数: "+objectMapper.writeValueAsString(laoleiConfig()));
		};
	}
}
